import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '医院',		name: 'hosp_id',	type: 'select', loading:true },
			{ label: '科室',		name: 'project_parent_id',	type: 'select', loading:true, idStr:'uuid',nameStr:'name' },
			{ label: '岗位',		name: 'project_id',	type: 'select', loading:true },
			{ label: '统计时间',		names: ['start_at','end_at'], type:'date-range' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			// 科室
			$fn.setRow( forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labCrisisCount',{
		isIndex:true,
		callback: data => this.setState({ result: data })
	})
	
	// 表单
	cols = [
		{ title: '医院', 							dataIndex: 'hosp_name', 					width:150 },
		{ title: '科室', 							dataIndex: 'project_parent_name', 			width:100 },
		{ title: '岗位', 							dataIndex: 'project_name', 					width:100 },
		{ title: '条码号', 							dataIndex: 'spec_code', 					...$fn.table.spec_code },
		{ title: '自然项目', 						dataIndex: 'parent_kind_name', 				width:150 },
		{ title: '检测项目名称', 					dataIndex: 'kind_name', 					width:150 },
		{ title: '检测结果', 						dataIndex: 'result', 						...$fn.table.time },
		{ title: '危急值结果批准时间', 				dataIndex: 'ts_approve_at', 				...$fn.table.time },
		{ title: '危急值结果电话报告时间', 			dataIndex: 'created_at', 					...$fn.table.time },
		{ title: '危急值电话报告与结果批准时间差', 	dataIndex: 'created_at', 					width:200 },
		{ title: '接收项目与结果批准时间差', 		dataIndex: 'receive2report_at', 			width:150 },
	]
	// 操作按钮
	controls = () => [
		Controls.exports.call(this, 'statistics/labCrisisCount'),			// 导出
	]
	
	render(){
		const { result } = this.state
		return (
			<>
				<Page title='实验室危急值统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{
						Table.call(this,
						{isIndex:true,isInit:window.isInit,
							suffix: (
								<>
									<div className='ml10 g9'>当前总接收项目与结果批准时间差 <b className='f14 c0'>{result?.current_page_total}</b></div>
								</>
							)
						})
					}
				</Page>
			</>
		)
	}
}

export default Index